package base.LRU;

/**
 * @author yanyun zhu
 * @version 1.0
 * @date 2021/12/22 15:23
 */
public class Solution {
    public static String longestCommonPrefix(String[] strs) {
        int length = strs.length;
        char[][] chars = new char[length][];
        int count = strs[0].length();

        StringBuilder builder = new StringBuilder();
        for(int j = 0; j < count; j ++){
            char a = strs[0].charAt(j);
            for(int i = 1; i < length; i++){
                if( i == strs[j].length() || a != strs[i].charAt(j) ){
                    return builder.toString();
                }
            }
            builder.append(a);
        }
        return builder.toString();
    }

    public static void main(String[] args) {
//        String[] strings = new String[]{"flower","flow","flight"};
//        String[] strings = new String[]{"dog","racecar","car"};
//        String[] strings = new String[]{"cir","car"};
        String[] strings = new String[]{"ab","a"};

        String s = longestCommonPrefix(strings);
        System.out.println(s);
    }
}
